package com.swotxu;

import com.swotxu.bean.Person;
import com.swotxu.config.MainConfig;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainTest {

	public static void main(String[] args) {
		// 配置注入
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean.xml");
		Person bean = (Person) applicationContext.getBean("person");
		System.out.println(bean);

		// 注解注入
		ApplicationContext context = new AnnotationConfigApplicationContext(MainConfig.class);
		Person person = context.getBean(Person.class);
		System.out.println(person);

		String[] beanNamesForType = context.getBeanNamesForType(Person.class);
		for (String name : beanNamesForType) {
			System.out.println(name);
		}
	}

}
